from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
import time


class Solution:
    primes = [11227] * 100

    # 判断n是否是素数
    def is_prime(self, n: int):
        i = 2
        while i * i <= n:

            if n % i == 0: return False
            i += 1
        return True

    def single_thread(self):
        for x in self.primes:
            self.is_prime(x)

    def multi_thread(self):
        with ThreadPoolExecutor() as pool:
            pool.map(self.is_prime, self.primes)

    def multi_process(self):
        with ProcessPoolExecutor() as pool:
            pool.map(self.is_prime, self.primes)


if __name__ == '__main__':
    start = time.time()
    Solution().single_thread()
    end = time.time()
    print("single_thread cost", end - start, "s")

    start = time.time()
    Solution().multi_thread()
    end = time.time()
    print("multi_thread cost", end - start, "s")

    start = time.time()
    Solution().multi_process()
    end = time.time()
    print("multi_process cost", end - start, "s")